package com.ruoyi.web.controller.monggo;

import com.github.pagehelper.PageInfo;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.system.domain.mongodb.AllSchool;
import com.ruoyi.system.domain.mongodb.Klasses;
import com.ruoyi.system.domain.mongodb.Schools;
import com.ruoyi.system.service.mongo.AllSchoolService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author yangtao
 * @since 2021-02-24 11:26
 */
@RestController
@RequestMapping("/sys/schools")
public class AllSchoolController {

    @Autowired
    private AllSchoolService schoolService;

    @GetMapping("/schoolList")
    public List<AllSchool> selectSchoolByCode(String eareCode){
        return schoolService.selectSchoolByCode(eareCode);
    }

    /**
     * 根据学校ID查询班级列表
     * @param schoolId
     * @return
     */
    @GetMapping("/classList")
    public List<Klasses> selectClassList(String schoolId){
        if (StringUtils.isEmpty(schoolId))
            return null;
        return schoolService.selectClassList(schoolId);
    }

    @RequestMapping("/save")
    public Integer saveSchool(Schools schools){
        return schoolService.save(schools);
    }

    @RequestMapping("selecSchoolPage")
    public PageInfo<Schools> selecSchoolPage(String schoolName,String eareCode,Integer pageNum,Integer pageSize){
        PageInfo<Schools> pageInfo = schoolService.selecSchoolPage(schoolName,eareCode,pageNum,pageSize);
        return pageInfo;
    }

    @RequestMapping("deleteSchoolById/{id}")
    public Integer deleteSchoolById(@PathVariable String id){
        schoolService.deleteSchoolById(id);
        return 1;
    }

    //修改学校
    @RequestMapping("updateSchool")
    public Integer updateSchool(String schoolId,String schoolName, String eareCode){
        return schoolService.updateSchool(schoolId,schoolName,eareCode);
    }

}
